package jf.collections.iterators;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.List;

import jf.collections.ListX;

/**
* @author ivanalx
* @date 01.06.2009 14:20:29
*/
public final class RightIterator<A> implements Iterator<A> {
	private List<A> list;

	private int index;

	public RightIterator(List<A> list) {
		this.list = list;
		index = list.size();
	}

	public boolean hasNext() {
		return index > 0;
	}

	public A next() {
		if (hasNext()) {
			return list.get(--index);
		} else {
			throw new NoSuchElementException();
		}
	}

	public void remove() {
		if (index > list.size() || index < 0) {
			throw new IllegalStateException();
		} else {
			list.remove(index);
		}
	}
}
